import { DeviceData } from './ble/BleClient';
import Log from './utils/Logger';

const TAG = 'DataHelper';

export interface IDataItem {
  id: number;
  name: string;
  enable: boolean;
  protocolType: number;
  taskId: number;
  // 其他已知字段...
}


export interface Details {
  groups: Group[];
}

export interface Group {
  id: number;
  name: string;
  points: Point[];
}

export interface Point {
  id: number;
  name: string;
  key: string;
  dataType: number;
  address: number;
  boolList: [{
    value,
    name
  }];
  enumList : [EnumItem];
  value?: ESObject;
}

export interface EnumItem {
  value: ESObject;
  name: ESObject;
}

export class DataHelper {
  private deviceData: DeviceData = undefined
  private taskItem: IDataItem[] = undefined
  private taskGroups: Group[] = undefined
  private selectGroupId: number = 0
  private selectId: number = 0

  private static instance: DataHelper;


  private constructor() {
  }

  public static getInstance(): DataHelper {
    if (!DataHelper.instance) {
      DataHelper.instance = new DataHelper();
    }
    return DataHelper.instance;
  }

  setDeviceData(deviceData: DeviceData) {
    this.deviceData = deviceData
  }

  getDeviceData() {
    return this.deviceData
  }

  setDataItem(taskItem: IDataItem[]) {
    this.taskItem = taskItem
  }

  getDataItem() {
    return this.taskItem
  }

  setTaskGroups(group: Group[]) {
    Log.info(TAG, `setTaskGroups ` + group)
    this.taskGroups = group
  }

  getTaskGroups() {
    return this.taskGroups
  }

  setSelectGroupId(selectGroupId: number) {
    this.selectGroupId = selectGroupId
  }

  getSelectGroupId() {
    return this.selectGroupId
  }

  setSelectId(selectId: number) {
    this.selectId = selectId
  }

  getSelectId() {
    return this.selectId
  }

  clear() {
    Log.info(TAG, `clear `)
    this.deviceData = undefined
    this.taskItem = undefined
    this.taskGroups = undefined
    this.selectGroupId = 0
    this.selectId = 0
  }
}